package net.starelement.gamelib.player;

import cn.nukkit.Player;
import cn.nukkit.level.Position;

import java.util.ArrayList;

/**  StarElement Listener 玩家集合类
 *
 * @author Ruok233
 * @since NukkitX API 1.0.9 | StarElement Project v1-alpaca
 *
 * cerate: 2019/12/15
 */
public class GamePlayerList {

    private ArrayList<Player> list = new ArrayList();

    //添加玩家
    public void add(Player player) {
        if (!list.contains(player)) {
            list.add(player);
        }
    }

    //删除玩家
    public void remove(Player player) {
        list.remove(player);
    }

    //发送TITLE
    public void sendTitle(String text) {
        for (int i = 0; i < list.size(); i++) {
            list.get(i).sendTitle(text);
        }
    }

    public void sendTitle(String text, String sub) {
        for (int i = 0; i < list.size(); i++) {
            list.get(i).sendTitle(text, sub);
        }
    }

    //传送
    public void teleport(Position position) {
        for (int i = 0; i < list.size(); i++) {
            list.get(i).teleport(position);
        }
    }

    //获取长度
    public int size() {
        return list.size();
    }

    //清空
    public void clear() {
        list.clear();
    }

    //清空背包
    public void clearInventory() {
        for (int i = 0; i < list.size(); i++) {
            list.get(i).getInventory().clearAll();
        }
    }

}
